package test4_16.demo04;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class URLTest {
    public static void main(String[] args) throws Exception {
        URL url = new URL("https://images.sj33.cn/uploads/202009/7-20092H12GA16.jpg");

        URLConnection urlConnection = url.openConnection();

        InputStream is = urlConnection.getInputStream();

        FileOutputStream fos = new FileOutputStream("D://a.jpg");

        byte[] bytes = new byte[1024];
        int size = -1;
        while ((size = is.read(bytes)) != -1) {
            fos.write(bytes, 0, size);
        }

        fos.close();
        is.close();
    }
}
